home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Resizer / Resample.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  2.7 KB  |  83 lines

  1. /* 
  2.  *  resample.cpp   - Original code from Avery Lee's Virtual Dub
  3.  *
  4.  *    Copyright (C) Alberto Vigata - ultraflask@yahoo.com - January 2000
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24.  
  25.  
  26. #include <crtdbg.h>
  27. #include <math.h>
  28.  
  29. //    void MakeCubic4Table(
  30. //        int *table,            pointer to 256x4 int array
  31. //        double A,            'A' value - determines characteristics
  32. //        mmx_table);            generate interleaved table
  33. //
  34. //    Generates a table suitable for cubic 4-point interpolation.
  35. //
  36. //    Each 4-int entry is a set of four coefficients for a point
  37. //    (n/256) past y[1].  They are in /16384 units.
  38. //
  39. //    A = -1.0 is the original VirtualDub bicubic filter, but it tends
  40. //    to oversharpen video, especially on rotates.  Use A = -0.75
  41. //    for a filter that resembles Photoshop's.
  42.  
  43.  
  44. void MakeCubic4Table(int *table, double A, bool mmx_table) throw() {
  45.     int i;
  46.  
  47.     for(i=0; i<256; i++) {
  48.         double d = (double)i / 256.0;
  49.         int y1, y2, y3, y4, ydiff;
  50.  
  51.         // Coefficients for all four pixels *must* add up to 1.0 for
  52.         // consistent unity gain.
  53.         //
  54.         // Two good values for A are -1.0 (original VirtualDub bicubic filter)
  55.         // and -0.75 (closely matches Photoshop).
  56.  
  57.         y1 = (int)floor(0.5 + (        +     A*d -       2.0*A*d*d +       A*d*d*d) * 16384.0);
  58.         y2 = (int)floor(0.5 + (+ 1.0             -     (A+3.0)*d*d + (A+2.0)*d*d*d) * 16384.0);
  59.         y3 = (int)floor(0.5 + (        -     A*d + (2.0*A+3.0)*d*d - (A+2.0)*d*d*d) * 16384.0);
  60.         y4 = (int)floor(0.5 + (                  +           A*d*d -       A*d*d*d) * 16384.0);
  61.  
  62.         // Normalize y's so they add up to 16384.
  63.  
  64.         ydiff = (16384 - y1 - y2 - y3 - y4)/4;
  65.         _ASSERT(ydiff > -16 && ydiff < 16);
  66.  
  67.         y1 += ydiff;
  68.         y2 += ydiff;
  69.         y3 += ydiff;
  70.         y4 += ydiff;
  71.  
  72.         if (mmx_table) {
  73.             table[i*4 + 0] = table[i*4 + 1] = (y2<<16) | (y1 & 0xffff);
  74.             table[i*4 + 2] = table[i*4 + 3] = (y4<<16) | (y3 & 0xffff);
  75.         } else {
  76.             table[i*4 + 0] = y1;
  77.             table[i*4 + 1] = y2;
  78.             table[i*4 + 2] = y3;
  79.             table[i*4 + 3] = y4;
  80.         }
  81.     }
  82. }
  83.